package ua.kharkov.knure.mikhaylov.st4.settings;

/**
 * Database query constants
 * 
 * @author Saint
 * 
 */
public class Query {

	public static final String USER_FIND_BY_ID = "SELECT * FROM " + Table.USERS
			+ " WHERE " + Field.ID + "=?";
	public static final String USER_FIND_BY_LOGIN = "SELECT * FROM "
			+ Table.USERS + " WHERE " + Field.USER_LOGIN + "=?";
	public static final String USER_UPDATE = "UPDATE " + Table.USERS + " SET "
			+ Field.USER_LOGIN + "=?, " + Field.USER_PASSWORD + "=?, "
			+ Field.USER_FIRST_NAME + "=?, " + Field.USER_LAST_NAME + "=?, "
			+ Field.USER_ROLE + "=? WHERE " + Field.ID + "=?";
	public static final String USER_FIND_ALL = "SELECT * FROM " + Table.USERS;
	public static final String USER_FIND_BY_ROLE_EXCEPT_ID = "SELECT * FROM "
			+ Table.USERS + " WHERE " + Field.USER_ROLE + "=? AND " + Field.ID
			+ " <>?";
	public static final String USER_INSERT = "INSERT INTO " + Table.USERS
			+ " VALUES (DEFAULT, ?, ?, ?, ?, ?)";

	public static final String VALUTA_FIND_ALL = "SELECT * FROM "
			+ Table.VALUTAS;

	public static final String ACCOUNT_FIND_ALL_BY_USER_ID = "SELECT * FROM "
			+ Table.ACCOUNTS + " WHERE " + Field.ACCOUNT_USER_ID + "=?";
	public static final String ACCOUNT_FIND_OPEN_BY_USER_ID = "SELECT * FROM "
			+ Table.ACCOUNTS + " WHERE " + Field.ACCOUNT_USER_ID + "=? AND "
			+ Field.ACCOUNT_STATE_ID + "=?";
	public static final String ACCOUNT_FIND_ALL_BY_USER_ID_AND_VALUTA = "SELECT * FROM "
			+ Table.ACCOUNTS
			+ " WHERE "
			+ Field.ACCOUNT_USER_ID
			+ "=? AND "
			+ Field.ACCOUNT_VALUTA_ID + "=?";
	public static final String ACCOUNT_FIND_OPEN_BY_USER_ID_AND_VALUTA = "SELECT * FROM "
			+ Table.ACCOUNTS
			+ " WHERE "
			+ Field.ACCOUNT_USER_ID
			+ "=? AND "
			+ Field.ACCOUNT_VALUTA_ID
			+ "=? AND "
			+ Field.ACCOUNT_STATE_ID
			+ "=?";
	public static final String ACCOUNT_FIND_BY_ID = "SELECT * FROM "
			+ Table.ACCOUNTS + " WHERE " + Field.ID + "=?";
	public static final String ACCOUNT_CREATE_NEW = "INSERT INTO "
			+ Table.ACCOUNTS + " VALUES(DEFAULT, ?, ?, ?, ?)";
	public static final String ACCOUNT_UPDATE_STATE = "UPDATE "
			+ Table.ACCOUNTS + " SET " + Field.ACCOUNT_STATE_ID + "=? WHERE "
			+ Field.ID + "=?";
	public static final String ACCOUNT_FIND_ALL_BLOCKED = "SELECT * FROM "
			+ Table.ACCOUNTS + " WHERE " + Field.ACCOUNT_STATE_ID + "=?";
	public static final String ACCOUNT_UPDATE_BALANCE = "UPDATE "
			+ Table.ACCOUNTS + " SET " + Field.ACCOUNT_BALANCE + "=? WHERE "
			+ Field.ID + "=?";

	public static final String CARD_FIND_ALL_BY_ACCOUNT_ID = "SELECT * FROM "
			+ Table.CARDS + " WHERE " + Field.CARD_ACCOUNT_ID + "=?";
	public static final String CARD_CREATE_NEW = "INSERT INTO " + Table.CARDS
			+ " VALUES (DEFAULT, ?, ?, ?)";
	public static final String CARD_DELETE_BY_ID = "DELETE FROM " + Table.CARDS
			+ " WHERE " + Field.ID + "=?";

	public static final String PAYMENT_FIND_BY_ID = "SELECT * FROM "
			+ Table.PAYMENTS + " WHERE " + Field.ID + "=?";
	public static final String PAYMENT_PREPARE = "INSERT INTO "
			+ Table.PAYMENTS + " VALUES(DEFAULT, ?, ?, ?, ?, ?)";
	public static final String PAYMENT_COUNT_BY_USER = "SELECT COUNT("
			+ Table.PAYMENTS + "." + Field.ID + ") FROM " + Table.PAYMENTS
			+ ", " + Table.ACCOUNTS + ", " + Table.USERS + " WHERE "
			+ Table.PAYMENTS + "." + Field.PAYMENT_PAYER_ID + "="
			+ Table.ACCOUNTS + "." + Field.ID + " AND " + Table.ACCOUNTS + "."
			+ Field.ACCOUNT_USER_ID + "=" + Table.USERS + "." + Field.ID
			+ " AND " + Table.USERS + "." + Field.ID + "=? AND "
			+ Table.PAYMENTS + "." + Field.PAYMENT_STATE_ID + "=?";
	public static final String PAYMENT_FIND_ALL_BY_USER_ID = "SELECT * FROM "
			+ Table.PAYMENTS + ", " + Table.ACCOUNTS + " WHERE ("
			+ Table.PAYMENTS + "." + Field.PAYMENT_PAYER_ID + "="
			+ Table.ACCOUNTS + "." + Field.ID + " OR " + Table.PAYMENTS + "."
			+ Field.PAYMENT_RECIEVER_ID + "=" + Table.ACCOUNTS + "." + Field.ID
			+ ") AND (" + Table.ACCOUNTS + "." + Field.ACCOUNT_USER_ID
			+ "=?) ORDER BY " + Table.PAYMENTS + "." + Field.ID + " DESC";
	public static final String PAYMENT_SET_STATE_BY_ID = "UPDATE "
			+ Table.PAYMENTS + " SET " + Field.PAYMENT_STATE_ID + "=? WHERE "
			+ Field.ID + "=?";
	public static final String PAYMENT_SET_STATE_BY_ACCOUNT_ID = "UPDATE "
			+ Table.PAYMENTS + " SET " + Field.PAYMENT_STATE_ID + "=? WHERE ("
			+ Field.PAYMENT_PAYER_ID + "=? OR " + Field.PAYMENT_RECIEVER_ID
			+ "=?) AND " + Field.PAYMENT_STATE_ID + "=?";

	private Query() {
	}

}
